package com.apop.accompanyH5.home;

import cn.hutool.core.bean.BeanUtil;
import com.apop.accompany.stuff.entity.Stuff;
import com.apop.accompany.stuff.service.StuffService;
import com.apop.accompanyH5.ServletUtils;
import com.apop.accompanyH5.home.service.HospitalService;
import com.apop.accompanyH5.order.domain.OrderDO;
import com.apop.accompanyH5.order.domain.vo.OrderReqVO;
import com.apop.accompanyH5.order.enums.OrderStateEnum;
import com.apop.accompanyH5.order.service.OrderService;
import com.apop.common.mapper.OneMapper;
import com.apop.common.model.PageResult;
import com.apop.common.model.Result;
import com.apop.common.util.OrderGenerator;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;

/**
 * 陪诊首页
 * @ClassName OneController
 * @author Jiayi Zheng
 * @date 2021/11/10 15:35
 * @Description: 测试
 * @version V1.0
 */
@RestController
@Slf4j
@RequestMapping("/pzH5/home")
public class HomeController {

    @Resource
    HospitalService hospitalService;

    @Resource
    StuffService stuffService;

    /**
     * 测试
     *
     * @return
     */
    @GetMapping("/test")
    @ResponseBody
    public Result test() {

        Map<String, Object> result = new HashMap();
        return Result.success(result);
    }

    /**
     * 首页数据
     *
     * @return
     */
    @GetMapping("/index")
    public Result index() {

        Map result = new HashMap();

        PageResult page = hospitalService.getHospitalList(1, 10);
        List list = (List) page.getList();
        result.put("hospitals", list);
        mockSlides(result);
        mockNav2s(result);

        return Result.success(result);
    }

    /**
     * 创建订单
     * @return
     */
    @GetMapping("/companion")
    public Result companion(){
        Map result = new HashMap();

        // 医院
        PageResult page = hospitalService.getHospitalList(1, 10);
        List list = (List) page.getList();
        result.put("hospitals", list);

        // 陪诊师列表
        PageResult pageResult = stuffService.getList(1, 10);
        List<Stuff> list1 = (List<Stuff>) pageResult.getList();
        result.put("companion", list1);

        return Result.success(result);
    }

    /**
     * 获取用户信息
     * @param request
     * @return
     */
    @GetMapping("/userInfo")
    public Result getUserInfo(HttpServletRequest request) {

        String account = ServletUtils.getCurrentUserAccount(request);

        Map result = new HashMap();
        result.put("username",account);
        result.put("nickname","admin");
        result.put("avatar","http://42.194.151.54:8090/image/avatar.jpg");
        return Result.success(result);
    }



    /**
     * 轮播数据
     *
     * @param response
     * @return
     */
    private Map mockSlides(Map<String, Object> response) {
        // 模拟数据源
        Map<String, Object> slide1 = new HashMap<>();
        slide1.put("id", 1);
        slide1.put("pic_url", "http://42.194.151.54:8090/image/1.png");
        slide1.put("stype", "0");
        slide1.put("stype_link", "");
        slide1.put("stype_text", "Stype 0");
        slide1.put("title", "banner02");

        Map<String, Object> slide2 = new HashMap<>();
        slide2.put("id", 2);
        slide2.put("pic_url", "http://42.194.151.54:8090/image/2.jpg");
        slide2.put("stype", "1");
        slide2.put("stype_link", "");
        slide2.put("stype_text", "Stype 1");
        slide2.put("title", "banner03");

        response.put("slides", new Object[]{slide1, slide2});

        return response;
    }

    /**
     * 导航图第一行
     *
     * @param response
     * @return
     */
    private Map mockNav2s(Map<String, Object> response) {
        // 模拟数据源
        Map<String, Object> slide1 = new HashMap<>();
        slide1.put("id", 1);
        slide1.put("pic_url", "http://42.194.151.54:8090/image/n1.jpg");
        slide1.put("stype", "0");
        slide1.put("stype_link", "");
        slide1.put("stype_text", "Stype 0");
        slide1.put("title", "banner02");

        Map<String, Object> slide2 = new HashMap<>();
        slide2.put("id", 2);
        slide2.put("pic_url", "http://42.194.151.54:8090/image/n2.jpg");
        slide2.put("stype", "1");
        slide2.put("stype_link", "");
        slide2.put("stype_text", "Stype 1");
        slide2.put("title", "banner03");

        response.put("nav2s", new Object[]{slide1, slide2});

        return response;
    }


}
